<?php

namespace app\common\service;

use \SMS\Zz253;
use \SMS\Huyi;
use \SMS\Hc;
use \SMS\Wz;
class SmsService{

	//国内
	public static function sms($quhao,$phone,$type=1){
		$limit_arr = ['18819468888','15834068536','15723713938','18076305695','17356032395','15328777418','18944916931','17791564538','17882450722'];

		//次数限制
		if(in_array($phone, $limit_arr)){
			return ['code' => 0, 'msg' => 'success'];
		}

		$num = C('send_ms_max');
		$count = model('PhoneCodeModel')->countPhone($phone);
		if ($count >= $num) {
			return ['code' => 1, 'msg' => '每日发送次数已达上限'];
		}
		$digits = C('sms_code_digits');
		$code   = rand('1'.str_repeat(0,$digits-1),str_repeat(9,$digits));
		//if($quhao == '+86'){
			// $res = Zz253::send($quhao,$phone,$code);
		// } else {
		// 	$res = Huyi::send($quhao,$phone,$code);
		// }
		$res = Wz::send2($quhao,$phone,$code);
		if ($res['code'] == 0) {
			$re = model('PhoneCodeModel')->addCode($phone, $code, $type);
			if ($re) {
				return ['code' => 0, 'msg' => 'success'];
			} else {
				return ['code' => 1, 'msg' => 'fail'];
			}
		} else {
			return ['code' => 1, 'msg' => $res['msg']];
		}
	}	
}